﻿/**
 *       Project: ServerLib
 *     Copyright: Copyright (C) 2008, Rob Kennedy
 *   Create Date: 2008-07-15 3:40 PM
 * Modified Date: 2008-07-15 3:40 PM    RK  Added comments
 *      Comments: Ignore SA1633.
 *      
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace ServerLib.Security
{
    using System;
    using System.Security;

    /// --------------------------------------------------------------------
    /// Project	 : ServerLib
    /// Class	 : UserAccount
    /// Inherits : None.
    /// --------------------------------------------------------------------
    /// <summary>
    /// Holds user account information for a user access/login account
    /// </summary>
    /// <authorname>Rob Kennedy</authorname>
    /// <remarks></remarks>
    /// --------------------------------------------------------------------
    public class UserAccount
    {
        #region Private Properties

        /// <summary>
        /// Contains a unique User ID number for the user account
        /// </summary>
        private int userId = 0;

        /// <summary>
        /// Contains a unique Session ID value for the user session
        /// </summary>
        private string sessionId = Guid.NewGuid().ToString();

        /// <summary>
        /// Contains a guid string value 
        /// </summary>
        private string uniqueId = Guid.NewGuid().ToString();

        /// <summary>
        /// Contains a user's password in secure memory space
        /// </summary>
        private SecureString password = new SecureString();

        /// <summary>
        /// Contains a user account user name
        /// </summary>
        private string userName = string.Empty;

        /// <summary>
        /// Contains a user account first name
        /// </summary>
        private string firstName = string.Empty;

        /// <summary>
        /// Contains a user account last name
        /// </summary>
        private string lastName = string.Empty;

        /// <summary>
        /// Contains a user account linked login name
        /// </summary>
        private string linkedAccount = string.Empty;

        /// <summary>
        /// Contains a challange string used in CRAM login
        /// </summary>
        private string challange = string.Empty;
        
        /// <summary>
        /// Contains a hash of the user's password used in CRAM login
        /// </summary>
        private SecureString hashValue = new SecureString();
        
        /// <summary>
        /// Contains the user account local mail drop folder
        /// </summary>
        private string mailFolder = string.Empty;

        /// <summary>
        /// Contains a collection of additional account attributes
        /// </summary>
        //private List<SettingAttribute> attributes = new List<SettingAttribute>();
        
        #endregion

        #region Public Properties
        /// <summary>
        /// Gets or sets the user password value
        /// </summary>
        public string Password
        {
            get
            {
                if (this.password != null)
                {
                    return System.Runtime.InteropServices.Marshal.PtrToStringUni(System.Runtime.InteropServices.Marshal.SecureStringToBSTR(this.password));
                }
                else
                {
                    return string.Empty;
                }
            }

            set
            {
                if (this.password != null && value != null)
                {
                    this.password.Clear();

                    foreach (char c in value.ToCharArray())
                    {
                        this.password.AppendChar(c);
                    }
                }
            }
        }

        /// <summary>
        /// Gets or sets the user hash value
        /// </summary>
        public string Hash
        {
            get
            {
                if (this.hashValue != null)
                {
                    return System.Runtime.InteropServices.Marshal.PtrToStringUni(System.Runtime.InteropServices.Marshal.SecureStringToBSTR(this.hashValue));
                }
                else
                {
                    return string.Empty;
                }
            }

            set
            {
                if (this.hashValue != null && value != null)
                {
                    this.hashValue.Clear();

                    foreach (char c in value.ToCharArray())
                    {
                        this.hashValue.AppendChar(c);
                    }
                }
            }
        }

        /// <summary>
        /// Gets or sets the user account unique session identifier
        /// </summary>
        public string SessionId
        {
            get
            {
                return this.sessionId;
            }

            set
            {
                this.sessionId = value;
            }
        }

        /// <summary>
        /// Gets or sets the unique challange string for the user session
        /// </summary>
        public string Challange
        {
            get
            {
                return this.challange;
            }

            set
            {
                this.challange = value;
            }
        }

        /// <summary>
        /// Gets the users unique identifier
        /// </summary>
        public string UniqueId
        {
            get
            {
                return this.uniqueId;
            }
        }

        /// <summary>
        /// Gets or sets the user name
        /// </summary>
        public string UserName
        {
            get
            {
                return this.userName;
            }

            set
            {
                this.userName = value;
            }
        }

        /// <summary>
        /// Gets or sets the user's first name
        /// </summary>
        public string FirstName
        {
            get
            {
                return this.firstName;
            }

            set
            {
                this.firstName = value;
            }
        }

        /// <summary>
        /// Gets or sets the user's last name
        /// </summary>
        public string LastName
        {
            get
            {
                return this.lastName;
            }

            set
            {
                this.lastName = value;
            }
        }

        /// <summary>
        /// Gets or sets the user's linked account login name
        /// </summary>
        public string LinkedAccount
        {
            get
            {
                return this.linkedAccount;
            }

            set
            {
                this.linkedAccount = value;
            }
        }

        /// <summary>
        /// Gets or sets the user account local mail drop folder
        /// </summary>
        public string MailFolder
        {
            get
            {
                return this.mailFolder;
            }

            set
            {
                this.mailFolder = value;
            }
        }

        /// <summary>
        /// Gets a collection of setting attributes for a user record
        /// </summary>
        //public List<SettingAttribute> Attributes
        //{
        //    get
        //    {
        //        return this.attributes;
        //    }
        //}
        #endregion
    }
}
